#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <sstream>
#include <limits>
#include <ctime>
using namespace std;
// 清屏函数,跨平台支持
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
// 显示标题界面
void showTitle() {
clearScreen();
cout << "" << endl;
cout << " 智能助手 - 小C " << endl;
cout << "" << endl;
cout << " 输入问题获取答案,输入'退出'结束对话 " << endl;
cout << " 输入'帮助'查看使用说明 " << endl;
cout << "==============================================" << endl << endl;
}
// 显示帮助信息
void showHelp() {
cout << "\n===== 使用帮助 =" << endl;
cout << "1. 直接输入问题即可获取答案" << endl;
cout << "2. 系统会自动识别关键词并尝试联想相关答案" << endl;
cout << "3. 无法回答的问题将自动使用Bing搜索" << endl;
cout << "4. 输入'退出'结束程序" << endl;
cout << "5. 输入'清除'清空屏幕" << endl;
cout << "6. 输入'帮助'显示此帮助信息" << endl;
cout << "7. 输入'主题'切换显示主题" << endl;
cout << "================\n" << endl;
}
// 转换字符串为小写
string toLower(const string& str) {
string result = str;
transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
// 移除字符串中的标点符号
string removePunctuation(const string& str) {
string result;
for (char c : str) {
if (ispunct(static_cast<unsigned char>(c)) == 0) {
result += c;
}
}
return result;
}
// 分割字符串为单词
vector<string> splitIntoWords(const string& str) {
vector<string> words;
stringstream ss(str);
string word;
}
// 处理用户输入,标准化
string processInput(const string& input) {
string processed = toLower(input);
processed = removePunctuation(processed);
return processed;
}
// 计算两个字符串的相似度(基于Jaccard系数)
double calculateSimilarity(const unordered_set<string>& words1, const unordered_set<string>& words2) {
if (words1.empty() || words2.empty()) return 0.0;
}
// 关键词联想 - 返回最相关的答案,优化版
vector<pair<string, double>> findRelatedAnswers(const string& input,
const unordered_map<string, string>& knowledgeBase) {
vector<pair<string, double>> related;
vector<string> inputWords = splitIntoWords(input);
unordered_set<string> uniqueInputWords(inputWords.begin(), inputWords.end());
}
// 打开网页进行搜索 - 使用Bing搜索引擎
void openWebSearch(const string& query) {
string encodedQuery;
// 简单的URL编码
for (char c : query) {
if (c == ' ') {
encodedQuery += "+";
} else if (isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '_' || c == '.' || c == '=' || c == '&') {
encodedQuery += c;
}
}
}
// 获取当前时间
string getCurrentTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
}
// 获取当前日期是星期几
string getWeekday() {
time_t now = time(0);
struct tm tstruct;
}
int main() {
// 预设的问答库 - 大幅扩展
unordered_map<string, string> knowledgeBase = {
// 问候与基本信息
{"你好", "你好!我是你的智能助手小C,有什么可以帮助你的吗?"},
{"再见", "再见!祝你有愉快的一天!"},
{"早上好", "早上好!新的一天开始了,祝你一切顺利!"},
{"晚上好", "晚上好!今天过得怎么样?"},
{"你叫什么名字", "我是一个控制台智能助手,你可以叫我小C。"},
{"现在时间", "当前时间是: " + getCurrentTime()},
{"今天星期几", "今天是" + getWeekday()},
{"你能做什么", "我可以回答各类常见问题,包括常识、科技、生活等方面。如果我无法回答,会帮你打开Bing搜索。"},
{"你是谁开发的", "我是由一位程序员用C++开发的智能助手。"},
{"你有什么功能", "我可以回答问题、提供信息、进行关键词联想,并在需要时帮你搜索网络。"},
{"你会学习吗", "目前我还不能主动学习,但开发者可以通过更新我的知识库来扩展我的能力。"},
{"很高兴认识你", "我也很高兴认识你!有什么我可以帮助你的吗?"},
{"谢谢你", "不客气!能帮到你我很开心。"},
}